Tips

An assorted collection of tips and hints.

Interactive JavaScript

Load the page
javascript: to enter an interactive evaluation session. Cool!

A word on crashing

As you write and debug your scripts, expect Netscape to crash. A lot. Many bugs will be ironed out for Navigator 3.0. For now, be patient and always, always save any work before testing JavaScript.

A word on sound

Although most Netscape browsers support ".au" audio sound files directly, some must run helper applications before the sounds can be played. Keep this in mind as you design your pages. If you assign click sound links to button presses, you may have to wait a minute or so for the press to be "heard"!

Images

Always, always, always include HEIGHT and WIDTH tags in your images. Early versions of Netscape Navigator 2.0 will not work correctly with your scripts unless these tags are included.

Debugging with "alert"

Use JavaScript's "alert()" as you would use C's printf() to keep track of your place and discover where your scripts are going wrong. Be careful, though! Avoid infinite loops or you may have to reboot the computer.

Line numbers in error reports

Don't even bother trying to match line numbers from error reports with your source code. The line numbers are whimsical at best and completely wrong almost always.

Professional hiding tip #1

Avoid greater-than signs in strings. Set a local variable to the > symbol tmp = unescape('%3E') and add it to your strings: document.write('<SCRIPT'+tmp)

Professional hiding tip #2

Avoid greater-than signs in comparisons. Instead of if (x > 3), use if (3 < x) or if (!(x <= 3)).

Professional hiding tip #3

Avoid decrement in math. Avoid i-- and use i -= 1 instead.

Alternating quotes

Make sure to alternate your quotes! Even when using the literal escape character (the backslash), for strings within strings, make sure to keep alternating. When those strings evaluate inside functions, methods, or event calls, unalternated strings may fail and cause runtime errors.

Functions with variable arguments

A function's arguments are stored in a property called arguments. You can check the length of this property to tell how many arguments are in use. For example:
function foo()
{
    var argv=foo.arguments
    var argc=foo.arguments.length
}


Copyright ©1998 by Charles River Media, All Rights Reserved